package com.wtb.dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.wtb.dao.OtDao;
import com.wtb.domain.Other;
import com.wtb.pub.WtbException;
import com.wtb.utils.JdbcUtils;
@SuppressWarnings("deprecation")
public class OtDaoImpl implements OtDao {
	private static final Log log = LogFactory.getLog(OtDaoImpl.class);
	
	public Other get(Other other) {
		try {
			QueryRunner qr = new QueryRunner();
			String sql = "select * from otdata where uni=?";
			other = (Other) qr.query(JdbcUtils.getConnection(), sql,other.getUni(),new BeanHandler(Other.class));
			return other;
		} catch (SQLException e) {
			log.error("查找otdata错误：", e);
			throw new WtbException("查找otdata错误"+e);
		}
	}

	public void insert(Other other) {
		try {
			QueryRunner qr = new QueryRunner();
			String sql = "insert into otdata(uni,para) values (?,?)";
			Object[] params = {other.getUni(),other.getPara()};
			qr.update(JdbcUtils.getConnection(), sql, params);
		} catch (SQLException e) {
			log.error("插入otdata错误：", e);
			throw new WtbException("插入otdata错误",e);
		}
	}

	public void update(Other other) {
		try {
			QueryRunner qr = new QueryRunner();
			String sql = "update otdata set para=? where uni=?";
			Object[] params = {other.getPara(),other.getUni()};
			qr.update(JdbcUtils.getConnection(), sql, params);
		} catch (SQLException e) {
			log.error("更新otdata错误：", e);
			throw new WtbException("更新otdata错误"+e);
		}
	}

}
